package com.ych.modules.api.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TUserCashOrderEntity;
import com.ych.modules.base.service.ITUserInfoService;
import com.ych.modules.common.entity.query.QueryUserCashOrderEntity;
import com.ych.modules.common.service.UserCashOrderService;
import com.ych.utils.TLMap;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/3/20
 * Time: 16:17
 * Description:
 */
@RestController("apiUserCashOrderController")
@RequestMapping("/api/auth/user/cashOrder")
@Api(tags = {"用户提现订单相关"}, description = "用户提现订单相关")
public class UserCashOrderController {
    @Autowired
    private UserCashOrderService userCashOrderService;
    @Autowired
    private ITUserInfoService    itUserInfoService;

    @PostMapping("/createCashOrder")
    @ApiOperation(value = "创建提现订单", notes = "创建提现订单")
    public R<String> createCashOrder(@RequestBody TUserCashOrderEntity entity) {
        try {
            itUserInfoService.validatePayPassword(TLMap.getUserId(), entity.getPassword());
            userCashOrderService.createCashOrder(entity);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listCashOrder")
    @ApiOperation(value = "查询提现订单列表", notes = "查询提现订单列表")
    public R<Page<TUserCashOrderEntity>> listCashOrder(@RequestBody QueryUserCashOrderEntity entity) {
        try {
            Page<TUserCashOrderEntity> page = userCashOrderService.listCashOrder(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/getCashOrder")
    @ApiOperation(value = "查询提现订单", notes = "查询提现订单")
    public R<TUserCashOrderEntity> getCashOrder(@RequestBody String orderId) {
        try {
            TUserCashOrderEntity entity = userCashOrderService.getCashOrder(orderId);
            return new R(0, "成功", entity);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
